//
// Created by xili on 2024/9/3 9:45.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    long long maxStrength(vector<int> &nums) {
        if (nums.size() < 2) {
            return nums[0];
        }
        vector<int> neg;
        long long ans = 0;
        for (auto &v: nums) {
            if (v == 0) {
                continue;
            }
            if (v > 0) {
                ans = ans == 0 ? v : ans * v;
            } else {
                neg.push_back(v);
            }
        }
        sort(neg.begin(), neg.end());
        int n = neg.size() - neg.size() % 2;
        for (int i = 0; i < n; i++) {
            ans = ans == 0 ? neg[i] : ans * neg[i];
        }
        return ans;
    }
};